Ext.onReady(function(){
	var editUrl='../hf/sortManager.do?action=ajaxEdit';
	var deleteUrl='../hf/sortManager.do?action=ajaxDelete';
	var listUrl='../hf/sortManager.do?action=ajaxList';
	var formSaveUrl='../hf/sortManager.do?action=ajaxSave';

	
	/*
	 * 查询过滤
	 */

	
	//加载从后台读取的数据
	//gridStore.load();

	//var temp=Ext.DomQuery.select('body');
	//定义form的字段
		var uniqueCode = new Ext.form.Hidden( {
			name : 'uniqueCode'
		});

		var sortName = new Ext.form.TextField( {
			fieldLabel : '分类名称',
			allowBlank : false,
			name : 'sortName',
			anchor : '80%'
		});

		var sortType = new Ext.form.TextField( {
			fieldLabel : '分类类型',
			allowBlank : false,
			name : 'sortType',
			anchor : '80%'
		});
		
		var inOrOut=new Ext.form.Radio({
			fieldLabel:'收入/支出',
			allowBlank:false,
			boxLabel:'收入',
			clearCls:'allow-float',		//允许两边浮动
			itemCls:'float-left',		//向左浮动
			name:'inOrOut',
			inputValue:'0',
			layout:'column'
		});
		var formFields=[
				uniqueCode,
				sortName,
				sortType,
				inOrOut,
				new Ext.form.Radio({
					boxLabel:'支出',
					labelWidth:0,
					hideLabel:true,
					name:'inOrOut',
					invalidText:'此项为必选选项',	
					showInvalidText:true,		//在此控件后添加错误提示
					labelSeparator:'',
					layout:'column',
					inputValue:'1'
				}),
				new Ext.form.NumberField({
					fieldLabel:'排列序号',
					emptyText:'请填写整数',
					anchor:'80%',
					allowDecimals:false,
					maxValue:200,
					minValue:0,
					name:'orderNo',
					itemCls:'stop-float'
				})
		];
	
	var filters = new Ext.grid.GridFilters({
	  filters:[
	    {type: 'string',  dataIndex: 'sortName'},
	    {type: 'string',  dataIndex: 'sortType'},
	    {type: 'numeric', dataIndex: 'orderNo'},
	    {type: 'date',  dataIndex: 'createDate'},
	    {type: 'boolean', dataIndex: 'inOrOut',yesText:'支出',noText:'收入'}
	]});
			
	
	new Ext.ux.GridExtend({
		editUrl:editUrl,
		deleteUrl:deleteUrl,
		listUrl:listUrl,
		formSaveUrl:formSaveUrl,
		el:'grid',
		sm:new Ext.grid.CheckboxSelectionModel({//start Ext.grid.CheckboxSelectionModel
			//选择全部时，只选择私有的分类
			selectAll : function(){
		        if(this.locked) return;
		        this.selections.clear();
		        for(var i = 0, len = this.grid.store.getCount(); i < len; i++){
		        	if(this.grid.store.data.items[i].json.isPublic!='0'){
		        		this.selectRow(i, true);
		        	}		            
		        }
		    },
		    //只属于私有的分类的行才有checkbox
		    renderer : function(v, p, record,rowIndex){
		    	if(record.json.isPublic!='0'){
		    		return '<div class="x-grid3-row-checker">&#160;</div>';
		    	}else{
		    		return ;
		    	}
		    }
		}),
		rowdblclick:function(grid, rowIndex, e){
			var selectId=this.gridStore.data.items[rowIndex].id;
			if(this.gridStore.data.items[rowIndex].json.isPublic=='0'){
				return;
			}
			this.editInfo(selectId);
		},
		formFields:formFields,
		filters:filters,
		cmDataArray:[{
			header:'分类名称',				//列名称
			dataIndex:'sortName',		//数据对应名称
			sortable: true
		},{
			header:'分类类型',				//列名称
			sortable: true,
			dataIndex:'sortType'			//数据对应名称
		},{
			header:'收入/支出',
			sortable: true,
			dataIndex:'inOrOut',
			renderer:function(value){
				if(value==1){
					return '支出';
				}else if(value==0){
					return '收入';
				}else{
					return ;
				}
			}
		},{
			header:'排列序号',
			sortable: true,
			dataIndex:'orderNo'
		},{
			header:'创建时间',
			sortable: true,
			dataIndex:'createDate'
		}]
	}).render();
    
});